package com.aaa.doctor.controller;


import com.aaa.doctor.feign.RegisteredItemFeign;
import com.aaa.doctor.service.PatientService;
import com.aaa.doctor.utils.IdWorker;
import com.aaa.doctor.vo.PatientVo;
import com.aaa.doctor.vo.PatientVoo;
import com.aaa.doctor.vo.Pvo;
import com.aaa.entity.Patient;
import com.aaa.entity.RegisteredItem;
import com.aaa.entity.Registration;
import com.aaa.vo.Result;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.metadata.IPage;
// import com.sun.org.apache.regexp.internal.RE;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @version 1.8.0_181
 * @Author ZXJ
 * @Date 2023/3/24 15:08
 * @注释
 */
@RestController
@RequestMapping("/doctor/patient")
public class PatientController {
    @Autowired
    private PatientService patientService;

    @Autowired
    private RegisteredItemFeign registeredItemFeign;

    /**
     * 分页查询所有患者patient信息
     * @return
     */
    @ApiOperation(value = "分页查询所有患者信息")
    @PostMapping("/searchPatient/{currentPage}/{pageSize}")
    public Result<IPage<Patient>> searchPatient(
            @ApiParam(value = "当前页码",required = true) @PathVariable Integer currentPage,
            @ApiParam(value = "每页的个数",required = true) @PathVariable Integer pageSize,
            @RequestBody PatientVo patientVo
    ){
        return patientService.searchPatient(currentPage,pageSize,patientVo);
    }

    /**
     * 根据患者id查询患者信息
     * @param patientId
     * @return
     */
    @ApiOperation(value = "根据患者id查询患者信息")
    @GetMapping("/getByPatientId/{patientId}")
    public Result<Patient> getByPatientId(@PathVariable String patientId){
        return patientService.getByPatientId(patientId);
    }

    /**
     * 根据idCard查询患者信息
     * @param idCard
     * @return
     */
    @ApiOperation(value = "根据idCard加载信息")
    @PostMapping("/getByidCardAll/{idCard}")
    public Result<Patient> getByidCardAll(@PathVariable String idCard){
        return patientService.getByidCardAll(idCard);
    }


    @ApiOperation(value = "查询所有挂号项目")
    @GetMapping("/getAll")
    public Result<List<RegisteredItem>> getAll(){
        return registeredItemFeign.getAll();
    }


    /**
     * 门诊挂号添加患者信息
     * @return
     */
    @ApiOperation(value = "添加患者信息")
    @PostMapping("/addPatient")
    public Result<String> addPatient(@RequestBody HashMap<String,Object> map){
        //JSON.parseObject，是将Json字符串转化为相应的对象
        Patient patient1 = JSON.parseObject(JSON.toJSONString(map.get("patient1")), Patient.class);
        System.out.println("patient111111111111111111111111111111 = " + patient1);
        Registration registration2 = JSON.parseObject(JSON.toJSONString(map.get("registration2")), Registration.class);
        System.out.println("registration2222222222222222222222222222 = " + registration2);
        Pvo pvo = JSON.parseObject(JSON.toJSONString(map.get("pvo")), Pvo.class);

        System.out.println("pvo = 0000000000000000000000000000" + pvo);
        return patientService.addPatient(patient1,registration2,pvo);
    }


    //查询档案/历史病历
    @GetMapping("/patientAllObject/{patientId}")
    public Result<Map<String,Object>> patientAllObject(@PathVariable String patientId){
        return patientService.patientAllObject(patientId);
    }




}
